package sogo.myi.micro.zuul.core;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

@Component
public class DemoFilter extends ZuulFilter {

	private static Logger log = LoggerFactory.getLogger(DemoFilter.class);

	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
		HttpServletRequest request = ctx.getRequest();
		String s = String.format("%s >>> %s", request.getMethod(), request.getRequestURL().toString());
		log.info(s);
		return null;
	}

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public int filterOrder() {
		return 0;
	}

	/**
	 * filterType：返回一个字符串代表过滤器的类型，在zuul中定义了四种不同生命周期的过滤器类型，具体如下： 1. pre：路由之前
	 * 2.routing：路由之时 3.post： 路由之后 4.error：发送错误调用
	 */
	@Override
	public String filterType() {
		return "pre";
	}

}
